<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">	
	
	<xsl:include href="../main.xsl" />
	<xsl:include href="menu.xsl" />
	<xsl:include href="../common/form.xsl" />
	<xsl:include href="albumBar.xsl" />
	
	<xsl:param name="albumId" select="data/response/@album-id" />

	<xsl:template match="/data">
		<html>
		
		<head>
			<title>
				<xsl:value-of select="$pageTitle" />
			</title>
			<xsl:call-template name="meta-head" />
			<link rel="stylesheet" href="{$baseURI}/css/photos/forms.css" type="text/css" media="all" />
			<link rel="stylesheet" href="{$baseURI}/css/owner-bar.css" type="text/css" media="all" />
			<script type="text/javascript" src="{$baseURI}/js/photos.js" />
		</head>
		<body>
			
			<xsl:call-template name="top-userbar" />

			<div class="page-header">
				<xsl:call-template name="logo" />

				<xsl:call-template name="menu" />
			</div>

			<div class="page-content-wrapper">
				<div class="page-blocks">
					<xsl:call-template name="default-blocks-top" />
				</div>
	
				<div class="page-content">
					<xsl:apply-templates select="response" />
				</div>
			</div>

			<xsl:call-template name="footer" />
		</body>
		</html>
	</xsl:template>
	
	<xsl:template match="response">
		<xsl:param name="oAlbum" select="document(concat('xobject://photoalbum/', $albumId))/data/object" />
		<xsl:param name="albumPreview" select="$oAlbum/property[@name='preview']/value" />
		
		<h1>
			<xsl:text>Редактирование фотографий в альбоме «</xsl:text>
			<a href="{$baseURI}/photoalbum/{$albumId}">
				<xsl:value-of select="$oAlbum/property[@name='title']/value" />
			</a>
			<xsl:text>»</xsl:text>
		</h1>
		
		<form method="post" enctype="multipart/form-data">
			<xsl:attribute name="action">
				<xsl:value-of select="concat ($baseURI, '/photos/edit/', @album-id, '/save?', ../@query-string)" />
			</xsl:attribute>
			
			<div class="edit-photos-list">
				<xsl:apply-templates select="form" mode="photo">
					<xsl:with-param name="albumPreview" select="$albumPreview" />
				</xsl:apply-templates>
			</div>
			
			<p>
				<input class="save" type="submit" value="Сохранить" />
			</p>
		</form>
	</xsl:template>
	
	<xsl:template match="form" mode="photo">
		<xsl:param name="albumPreview" />
		<xsl:param name="photoId" select="@prefix" />
		<xsl:param name="src" select="concat ($baseURI, '/thumb_100_100', field[@name='photo']/value)" />
		
		<div class="item" id="photo_{@prefix}">
			<div class="block">
				<div class="photo">
					<a href="{$baseURI}/photos/photo/{$photoId}">
						<img alt="" src="{$src}" />
					</a>
				</div>
				
				<div class="controls">
					<div class="control preview" id="set_preview_{$photoId}">
						<xsl:if test="$albumPreview = field[@name='photo']/value">
							<xsl:attribute name="class">control preview selected</xsl:attribute>
							<xsl:text>Обложка альбома</xsl:text>
						</xsl:if>
						
						<xsl:if test="$albumPreview != field[@name='photo']/value">
							<a href="#" onclick="PhotoEdit.setAlbumPreview({$albumId}, {$photoId}); return false;">Обложка альбома</a>
						</xsl:if>
					</div>
					<div class="control move">
						<span>Переместить в</span>
						<select name="data[{$photoId}][album_id]">
							<option value="{$albumId}"></option>
							
							<xsl:apply-templates select="document('xmodule://photos/getUserAlbumsSelection')/data/response/object" mode="album-option">
								<xsl:sort select="property[@name='title']/value" />
							</xsl:apply-templates>
							
						</select>
					</div>
					<div class="control delete">
						<a href="#" onclick="PhotoEdit.delete({$albumId}, {$photoId}); return false;">Удалить</a>
					</div>
				</div>
			</div>
			
			<div class="info">
				<dl>
					<dt>Описание:</dt>
					<dd>
						<textarea name="data[{$photoId}][description]">
							<xsl:value-of select="field[@name='description']/value" />
						</textarea>
					</dd>
				</dl>
				<dl>
					<dt>Теги:</dt>
					<dd>
						<input type="text" name="data[{$photoId}][tags]">
							<xsl:attribute name="value">
								<xsl:value-of select="field[@name='tags']/value" />
							</xsl:attribute>
						</input>
					</dd>
				</dl>
			</div>
		</div>
	</xsl:template>
	
	<!-- ALBUM OPTION -->
	<xsl:template match="object[@type='photoalbum']" mode="album-option">
		<option value="{@id}">
			<xsl:value-of select="property[@name='title']/value" />
		</option>
	</xsl:template>
	
</xsl:stylesheet>